package com.yupi.springbootinit.manager;

import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.yucongming.dev.client.YuCongMingClient;
import com.yupi.yucongming.dev.common.BaseResponse;
import com.yupi.yucongming.dev.model.DevChatRequest;
import com.yupi.yucongming.dev.model.DevChatResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: hxu
 * @Date: 2024/05/28/17:31
 * @Description:
 */
@Service
public class AiManager {
    @Resource
    private YuCongMingClient yuCongMingClient;

    public String doChat(long modeId, String message) {
        DevChatRequest devChatRequest = new DevChatRequest();
        devChatRequest.setModelId(modeId);
        devChatRequest.setMessage(message);
        BaseResponse<DevChatResponse> baseResponse = yuCongMingClient.doChat(devChatRequest);
        if (baseResponse == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "AI响应异常");
        }
        return baseResponse.getData().getContent();
    }

}
